package common

import (
	"clientDemo/ui/fyne_ui/widget/interface"
)

type WidgetUserInfo struct {
	Type           string
	Name           string
	BaseWidgetName string
	SkinTempName   string
	Properties     map[string]*Property
	PropertyList   []*Property
	Attribute      map[string]*Property
	AttributeList  []*Property
	UserInfo       map[string]string
	Action         []string //后面再加

	IsSkin bool
	IsRoot bool

	pWidgetInfo WidgetInfo
	pNode       widgetcommon.IWidgetItem
	//pChildList  []*WidgetUserInfo
}

func NewWidgetUserInfo(Name, SkinName string, node widgetcommon.IWidgetItem) *WidgetUserInfo {
	return &WidgetUserInfo{
		Type:         "",
		Name:         Name,
		SkinTempName: SkinName,
		Properties:   map[string]*Property{},
		Attribute:    map[string]*Property{},
		UserInfo:     map[string]string{},
		Action:       []string{},
		IsSkin:       false,
		IsRoot:       false,
		pNode:        node,
	}
}
func (w *WidgetUserInfo) SetProperty(key, value string, isProperty bool) {
	if !isProperty {
		return
	}
	pro, ok := w.Properties[key]
	if ok {
		pro.Value = value
		return
	}
	obj := &Property{
		Key:   key,
		Value: value,
	}
	w.Properties[key] = obj
	w.PropertyList = append(w.PropertyList, obj)
}
func (w *WidgetUserInfo) SetAttribute(key, value string) {
	pro, ok := w.Attribute[key]
	if ok {
		pro.Value = value
		return
	}
	obj := &Property{
		Key:   key,
		Value: value,
	}
	w.Attribute[key] = obj
	w.AttributeList = append(w.AttributeList, obj)
	w.pNode.SetProperty(key, value, false)
}

func (w *WidgetUserInfo) ForEachProperty(cb func(key, value string)) {
	for i := 0; i < len(w.PropertyList); i++ {
		v := w.PropertyList[i]
		if v == nil {
			continue
		}
		cb(v.Key, v.Value)
	}
}
func (w *WidgetUserInfo) GetName() string {
	return w.Name
}
func (w *WidgetUserInfo) GetSkinTempName() string {
	return w.SkinTempName
}

func (w *WidgetUserInfo) GetBaseWidgetName() string {
	return w.BaseWidgetName
}

//func (w *WidgetUserInfo) SetAttribute(key, value string) {
//	w.Properties[key] = value
//}
